﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using KCL.Code.Data;

namespace KCL.Input
{
    /// <summary>
    /// Summary description for InputFinishedProduct1
    /// </summary>
    public class InputFinishedProduct1 : IHttpHandler
    {
        public void ProcessRequest(HttpContext context)
        {
            string orderMaterialIdList = context.Request.Form["orderMaterialIdList"].ToString();
            string orderMaterialFinishedQuantity = context.Request.Form["orderMaterialFinishedQuantity"].ToString();
            int orderId = Convert.ToInt32(context.Request.Form["orderId"]);         

            context.Response.ContentType = "application/html";
            var responseData = string.Empty;

            try
            {
                InputFinishedProductDAO dao = new InputFinishedProductDAO();
                bool isUpdated = dao.UpdateQuantity(orderMaterialIdList, orderMaterialFinishedQuantity, orderId);
                if (isUpdated == true)
                {
                    context.Response.Write("alert('Chỉnh sửa thành công.'); window.location.replace('../Management/OrderManagement.aspx');");
                }
                else
                {
                    context.Response.Write(string.Format("alert(\"Có lỗi: {0}\");"));
                }
            }
            catch (Exception ex)
            {
                context.Response.Write(string.Format("alert(\"Có lỗi: {0}\");", ex.Message.Replace("\r\n", "\\n")));
                return;
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}